package com.suzhouhe.util.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * 时间工具
 *
 * @author suzhouhe
 * @date 2020-11-03 17:46
 **/
public class DateUtil {

    /**
     * 将时间戳转换为LocalDateTime
     *
     * @param time 时间戳
     * @return LocalDateTime
     */
    public static LocalDateTime longToLocalDateTime(Long time) {
        AssertUtil.nullTrw(time, "时间参数为空");
        return Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault()).toLocalDateTime();
    }

    /**
     * 将时间戳转换为LocalDateTime
     *
     * @param time LocalDateTime
     * @return 时间戳
     */
    public static Long localDateTimeToLong(LocalDateTime time) {
        AssertUtil.nullTrw(time, "时间参数为空");
        return time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }
}
